<template>
  <div class="common-page">
    <SearchForm
      :search-list="searchList"
      :search-params="searchParams"
      @search="onSearch"
      @reset="onReset"
    />
    <div class="table-box">
      <el-table
        v-loading="loading"
        height="100%"

        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >

        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="项目状态">
          <template slot-scope="scope">
            <StatusTag :status="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="400px">
          <template slot-scope="scope">
            <el-button type="primary" @click="onRead(scope.row)" style="width: 90px;">查看详情</el-button>
            <el-button type="primary" @click="onUpload(scope.row)" style="width: 90px;">资料上传</el-button>
            <el-button
              v-if="scope.row.status == 2"
              type="primary"
              style="width: 90px;"
              @click="onApplyRoom(scope.row)"
            >申请会议室</el-button>
            <!--               -->
            <el-button
              v-if="scope.row.status == 7"
              type="primary"
              style="width: 90px;"
              @click="onChangeMeeting(scope.row)"
            >会议调整</el-button>
            <el-button
              v-if="scope.row.status > 3 && scope.row.status != 6"
              type="primary"
              style="width: 90px;"
              @click="onDelete(scope.row)"
            >取消会议</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
    <Detail ref="MeetingDetailRef" />
    <DataUpload ref="DataUploadRef" :current-detail="currentDetail"/>
    <ApplyRoom ref="ApplyRoomRef" @get-page="onSearch" />
    <MeetingChange :current-detail="currentDetail" ref="MeetingChangeRef" @get-page="onSearch"/>
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import { http } from '@/api'
import { getName, Investor, ProjectStatus, ProjectType, EnterpriseType } from '@/dict'
import Detail from './detail'
import DataUpload from './data-upload'
import ApplyRoom from '@/views/meeting/apply/apply-room'
import MeetingChange from "./meeting-change";

export default {
  name: 'Index',
  components: {
    ApplyRoom,
    Detail,
    DataUpload,
      MeetingChange
  },
  mixins: [crud],
  data() {
    return {
      request: http.meeting_apply,
      searchList: [
        {
          key: 'projectName',
          name: 'input',
          label: '项目名称'
        },
        {
          key: 'timeValue',
          name: 'datetime',
          valueFormat: 'yyyy-MM-dd',
          dateType: 'daterange',
          label: '时间'
        }
      ],
      searchParams: {
        meetingName: '',
        timeValue: []
      },
      columns: [
        { prop: 'projectName', label: '项目名称' },
        { prop: 'departName', label: '会议发起单位' },
        { prop: 'meetingStartTime', label: '会议开始时间' },
        { prop: 'meetingName', label: '会议室' }
      ],
      tableData: [

      ],
      professorList: [],
      deptList: [],
      deleteText: '确认取消？'
    }
  },
  methods: {
    formatTableData(data) {
      data.forEach(el => {
        el.projectTypeName = getName(el.projectType, ProjectType)
        // el.investorName = getName(el.investor, Investor)
        el.statusName = getName(el.status, ProjectStatus)
        el.enterpriseTypeName = getName(el.enterpriseType, EnterpriseType)
      })
    },
    onRead(item) {
      this.$refs.MeetingDetailRef.open(item)
    },
    onUpload(item) {
      this.$refs.DataUploadRef.open(item)
    },
    onApplyRoom(item) {
      this.$refs.ApplyRoomRef.open(item)
    },
    onChangeMeeting(item) {
      this.currentDetail = item
      this.$refs.MeetingChangeRef.open(item)
    },
    onNextProfessor(list) {
      this.professorList = list
      this.$refs.DeptListRef.open(this.deptList)
    },
    onTotal(list) {
      this.deptList = list
      this.$refs.TotalListRef.open(this.professorList, this.deptList)
    },
    onPreProfessor(list) {
      this.deptList = list
      this.onChangeMeeting()
    },
    onPreTotal() {
      this.$refs.DeptListRef.open(this.deptList)
    },
    reset() {
      this.professorList = []
      this.deptList = []
    }
  }
}
</script>

<style scoped lang="scss">
</style>
